package com.tanhua.test;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
import com.aliyun.teaopenapi.models.Config;

public class Sample {

    public static void main(String[] args_) throws Exception {

        // 手动输入 accessKeyId (之后动态配置)
        String accessKeyId = "****";
        String accessKeySecret= "****";

        // 配置对象阿里云
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";

        // 创建请求客户端对象
        com.aliyun.dysmsapi20170525.Client client =  new com.aliyun.dysmsapi20170525.Client(config);

        // 设置短信参数
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("18618412321") //目标手机号
                .setSignName("物流云商") //签名名称
                .setTemplateCode("SMS_205134115") //短信模板code
                .setTemplateParam("{\"code\":\"1234\"}"); //模板中变量替换

        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse response = client.sendSms(sendSmsRequest);

        // response.body.message  code = OK 代表成功
        SendSmsResponseBody body = response.getBody();
        System.out.println(body.getMessage());
    }
}